package com.njtoyo.taxi.admin.service.business.geo.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njtoyo.taxi.admin.mapper.master.entity.VehicleModel;
import com.njtoyo.taxi.admin.mapper.master.mapper.VehicleModelMapper;
import com.njtoyo.taxi.admin.service.business.geo.VehicleModelService;
import com.taxi.entity.common.RestResult;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VehicleModelServiceImpl extends ServiceImpl<VehicleModelMapper, VehicleModel> implements VehicleModelService {
    @Override
    public RestResult page(Integer current, Integer size) {
        Page<VehicleModel> page = new Page<>(current, size);
        IPage<VehicleModel> pages = baseMapper.selectPage(page,null);
        return RestResult.success( pages);
    }

    @Override
    public RestResult add(VehicleModel vehicleModel) {
        vehicleModel.setCreatedAt(DateUtil.date());
        baseMapper.insert(vehicleModel);
        return RestResult.success();
    }

    @Override
    public RestResult update(VehicleModel vehicleModel) {
        vehicleModel.setCreatedAt(DateUtil.date());
        baseMapper.updateById(vehicleModel);
        return RestResult.success();
    }

    @Override
    public RestResult listAll() {
        List<VehicleModel> list = baseMapper.selectList(null);
        return RestResult.success(list);
    }
}
